package com.waqwb.entity;

import java.util.ArrayList;
import java.util.Iterator;

public class Cart {
	private ArrayList<BookItem> itemList = new ArrayList<BookItem>();
	public ArrayList<BookItem> getItemList() {
		return itemList;
	}

	public void setItemList(ArrayList<BookItem> itemList) {
		this.itemList = itemList;
	}

	public double getSave() {
		double all = 0;
		for (BookItem item : itemList) {
			all += item.getSave();
		}
		return all;
	}

	public double getTotalAcount() {
		double all = 0;
		for (BookItem item : itemList) {
			all += item.getTotalAcount();
		}
		return all;
	}

	public void update(int id, int num) {
		for (BookItem item : itemList) {
			if (item.getBook().getId() == id) {
				item.setCount(num);
			}
		}
	}

	public void delete(int id){
		Iterator<BookItem> it= itemList.iterator();
		while(it.hasNext()){
			BookItem item=it.next();
			if(item.getBook().getId()==id){
				it.remove();
			}
		}
	}
}
